//处理道具及碰撞的脚本
cc.Class({
    extends: cc.Component,

    properties: {
        type: 0,//道具类型 0加速 1加力量 2加方向
        colorBg: cc.Node
    },

    onCollisionEnter: function (other) {
        //当道具碰到英雄后，把这个英雄的属性都设置一下
        if (this.type == 0) {
            other.getComponent("role").setInPropSpeed(this.colorBg.color);
        } else if (this.type == 1) {
            other.getComponent("role").setInPropPower(this.colorBg.color);
        }else if(this.type==2){
            other.getComponent("role").setInPropMult(this.colorBg.color);
        }
        this.node.runAction(cc.sequence(cc.fadeOut(0.2),cc.callFunc(function(){
            this.node.destroy();
        }.bind(this),this)));
        this._game.soundHelper().playCollect();
    },

    initData:function(game,speed,rect){
      this._game=game;
      this._rect=rect;
      this._speed=speed;
    },

    move:function(dt){
        let nowY=this.node.y-this._speed*dt;
        this.node.position=cc.p(this.node.x,nowY);
        if(nowY<-this._rect.height/2-this.node.height/2-50){
           this.node.destroy();
        }
    },

    // LIFE-CYCLE CALLBACKS:
    onLoad() {
        //道具初始化
        this.colorBg.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.2, 1.2, 1.2), cc.scaleTo(0.1, 1, 1))));
    },

    start() {

    },

    update (dt) {
        this.move(dt);
    },
});
